package com.ht.module.file.controller;

import com.ht.config.log.annotation.SysLog;
import com.ht.config.minio.service.MinioService;
import com.ht.constant.DicConstants;
import com.ht.module.file.entity.FileInfo;
import com.ht.util.JsonResult;
import com.ht.util.Pager;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.ht.module.file.entity.FileFolder;
import com.ht.module.file.service.FileFolderService;
import com.ht.util.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * <p>
 * 文件夹表 前端控制器
 * </p>
 *
 * @author hejialun
 * @since 2024-06-12
 */
@RestController
@RequestMapping("/file-folder")
public class FileFolderController {

    
    @Autowired
    private FileFolderService fileFolderService;

    @ApiOperation("获取当前用户文件夹目录树")
    @GetMapping("/findFolderTreeByLogin")
    public JsonResult findFolderTreeByLogin(){
        return JsonResult.success(fileFolderService.findFolderTreeByLogin());
    }



    @ApiOperation("按层级查询当前登录用户的文件夹")
    @GetMapping("/findLoginUserFolderByPId/{pid}")
    public JsonResult findMyFolderByPId(FileFolder en,@PathVariable(value = "pid") String pid){
        return JsonResult.success(fileFolderService.findLoginUserFolderByPId(en,pid));
    }



    @ApiOperation("新增")
    @PostMapping("/add")
    @SysLog(msg = "新增文件夹",type = DicConstants.OperLogType.ADD)
    public JsonResult add(@RequestBody @Valid FileFolder en){
	    CommMethod.beanCreate(en);
        fileFolderService.save(en);
        return JsonResult.success();
    }


    @ApiOperation("删除权限范围内的文件夹")
    @SysLog(msg = "删除权限范围内的文件夹",type = DicConstants.OperLogType.DEL)
    @DeleteMapping("/delFolder/{id}")
    public JsonResult delFolderByFolderId(@PathVariable String id) {
        fileFolderService.delFolderByFolderId(id);
        return JsonResult.success();
    }


    @ApiOperation("修改")
    @SysLog(msg = "修改文件夹",type = DicConstants.OperLogType.UPDATE)
    @PutMapping("/update")
    public JsonResult updateById(@RequestBody @Valid FileFolder en){
	    CommMethod.beanUpdate(en);
        fileFolderService.updateById(en);
        return JsonResult.success();
    }




}
